from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-02-24 14:02:09.465655
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 24, Feb, 2022
Time: 14:02:14
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.2529
Nobs: 577.000 HQIC: -48.6676
Log likelihood: 6838.52 FPE: 5.60834e-22
AIC: -48.9326 Det(Omega_mle): 4.80478e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.349788 0.068197 5.129 0.000
L1.Burgenland 0.107307 0.041445 2.589 0.010
L1.Kärnten -0.110913 0.021606 -5.133 0.000
L1.Niederösterreich 0.188619 0.086510 2.180 0.029
L1.Oberösterreich 0.129912 0.085531 1.519 0.129
L1.Salzburg 0.255869 0.043873 5.832 0.000
L1.Steiermark 0.036691 0.057958 0.633 0.527
L1.Tirol 0.101243 0.046757 2.165 0.030
L1.Vorarlberg -0.069327 0.041237 -1.681 0.093
L1.Wien 0.017890 0.075987 0.235 0.814
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.052598 0.147023 0.358 0.721
L1.Burgenland -0.038046 0.089348 -0.426 0.670
L1.Kärnten 0.041407 0.046580 0.889 0.374
L1.Niederösterreich -0.204794 0.186502 -1.098 0.272
L1.Oberösterreich 0.460622 0.184392 2.498 0.012
L1.Salzburg 0.282230 0.094584 2.984 0.003
L1.Steiermark 0.113903 0.124949 0.912 0.362
L1.Tirol 0.304678 0.100802 3.023 0.003
L1.Vorarlberg 0.025542 0.088901 0.287 0.774
L1.Wien -0.028718 0.163816 -0.175 0.861
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.198713 0.034806 5.709 0.000
L1.Burgenland 0.088125 0.021152 4.166 0.000
L1.Kärnten -0.007429 0.011027 -0.674 0.500
L1.Niederösterreich 0.239216 0.044152 5.418 0.000
L1.Oberösterreich 0.163013 0.043652 3.734 0.000
L1.Salzburg 0.039126 0.022391 1.747 0.081
L1.Steiermark 0.026983 0.029580 0.912 0.362
L1.Tirol 0.081619 0.023863 3.420 0.001
L1.Vorarlberg 0.053707 0.021046 2.552 0.011
L1.Wien 0.118917 0.038781 3.066 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118998 0.034785 3.421 0.001
L1.Burgenland 0.042282 0.021139 2.000 0.045
L1.Kärnten -0.013112 0.011021 -1.190 0.234
L1.Niederösterreich 0.168928 0.044126 3.828 0.000
L1.Oberösterreich 0.338455 0.043626 7.758 0.000
L1.Salzburg 0.099521 0.022378 4.447 0.000
L1.Steiermark 0.111481 0.029562 3.771 0.000
L1.Tirol 0.090002 0.023849 3.774 0.000
L1.Vorarlberg 0.060970 0.021034 2.899 0.004
L1.Wien -0.017927 0.038758 -0.463 0.644
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.124974 0.065519 1.907 0.056
L1.Burgenland -0.045280 0.039817 -1.137 0.255
L1.Kärnten -0.045410 0.020758 -2.188 0.029
L1.Niederösterreich 0.135348 0.083112 1.628 0.103
L1.Oberösterreich 0.162964 0.082172 1.983 0.047
L1.Salzburg 0.285199 0.042150 6.766 0.000
L1.Steiermark 0.057525 0.055682 1.033 0.302
L1.Tirol 0.157280 0.044921 3.501 0.000
L1.Vorarlberg 0.097302 0.039618 2.456 0.014
L1.Wien 0.073216 0.073002 1.003 0.316
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.079659 0.051047 1.560 0.119
L1.Burgenland 0.025293 0.031022 0.815 0.415
L1.Kärnten 0.053499 0.016173 3.308 0.001
L1.Niederösterreich 0.188773 0.064755 2.915 0.004
L1.Oberösterreich 0.331602 0.064022 5.179 0.000
L1.Salzburg 0.033628 0.032840 1.024 0.306
L1.Steiermark 0.005921 0.043383 0.136 0.891
L1.Tirol 0.119635 0.034999 3.418 0.001
L1.Vorarlberg 0.066268 0.030867 2.147 0.032
L1.Wien 0.097450 0.056878 1.713 0.087
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170436 0.061685 2.763 0.006
L1.Burgenland 0.004425 0.037487 0.118 0.906
L1.Kärnten -0.065987 0.019543 -3.376 0.001
L1.Niederösterreich -0.107561 0.078249 -1.375 0.169
L1.Oberösterreich 0.209153 0.077364 2.703 0.007
L1.Salzburg 0.053580 0.039684 1.350 0.177
L1.Steiermark 0.248503 0.052424 4.740 0.000
L1.Tirol 0.499594 0.042293 11.813 0.000
L1.Vorarlberg 0.064501 0.037300 1.729 0.084
L1.Wien -0.073409 0.068731 -1.068 0.285
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161583 0.068425 2.361 0.018
L1.Burgenland -0.002494 0.041583 -0.060 0.952
L1.Kärnten 0.062888 0.021679 2.901 0.004
L1.Niederösterreich 0.165115 0.086800 1.902 0.057
L1.Oberösterreich -0.054146 0.085818 -0.631 0.528
L1.Salzburg 0.208178 0.044020 4.729 0.000
L1.Steiermark 0.138726 0.058152 2.386 0.017
L1.Tirol 0.055798 0.046914 1.189 0.234
L1.Vorarlberg 0.146994 0.041375 3.553 0.000
L1.Wien 0.120506 0.076241 1.581 0.114
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.392126 0.040149 9.767 0.000
L1.Burgenland -0.004102 0.024399 -0.168 0.866
L1.Kärnten -0.021305 0.012720 -1.675 0.094
L1.Niederösterreich 0.200460 0.050930 3.936 0.000
L1.Oberösterreich 0.231024 0.050354 4.588 0.000
L1.Salzburg 0.036553 0.025829 1.415 0.157
L1.Steiermark -0.016739 0.034121 -0.491 0.624
L1.Tirol 0.090383 0.027527 3.283 0.001
L1.Vorarlberg 0.051055 0.024277 2.103 0.035
L1.Wien 0.043436 0.044735 0.971 0.332
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036356 0.100967 0.168021 0.137720 0.094426 0.080803 0.032428 0.208606
Kärnten 0.036356 1.000000 -0.027722 0.132285 0.048300 0.085351 0.443758 -0.067286 0.089155
Niederösterreich 0.100967 -0.027722 1.000000 0.310286 0.117796 0.269836 0.065681 0.151019 0.288007
Oberösterreich 0.168021 0.132285 0.310286 1.000000 0.212373 0.293780 0.166839 0.135003 0.235460
Salzburg 0.137720 0.048300 0.117796 0.212373 1.000000 0.122488 0.090672 0.104347 0.122297
Steiermark 0.094426 0.085351 0.269836 0.293780 0.122488 1.000000 0.134386 0.105885 0.032541
Tirol 0.080803 0.443758 0.065681 0.166839 0.090672 0.134386 1.000000 0.062356 0.151331
Vorarlberg 0.032428 -0.067286 0.151019 0.135003 0.104347 0.105885 0.062356 1.000000 -0.005571
Wien 0.208606 0.089155 0.288007 0.235460 0.122297 0.032541 0.151331 -0.005571 1.000000